package 第二章数据结构.队列.id829模拟队列;

import java.util.Scanner;

/**
 * 数组模拟队列
 */
public class Main {
    public static void main(String[]args){
        MyQueue queue = new MyQueue();
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        scanner.nextLine();
        while (m -- > 0){
            String s = scanner.nextLine();
            String[] op = s.split(" ");
            if(op[0].equals("push")){
                queue.push(Integer.parseInt(op[1]));
            }else if(op[0].equals("pop")){
                queue.pop();
            }else if(op[0].equals("query")){
                int ret = queue.query();
                System.out.println(ret);
            }else if(op[0].equals("empty")){
                boolean isEmpty = queue.empty();
                if(isEmpty) System.out.println("YES");
                else System.out.println("NO");
            }
        }
    }

    static class MyQueue{
        static int[] arrays = new int[100001];
        static int head;
        static int tail;

        static void push(int x){
            tail++;
            arrays[tail] = x;
        }
        static void pop(){
            head++;
        }
        static int query(){
            return arrays[head+1];
        }
        static boolean empty(){
            return head == tail;
        }
    }
}

